<template>
    <view>
        <view v-if="nurseInfo" class="margin radius-lg solid shadow bg-gradual-blue">
            <view class="cu-bar  margin-top-sm grid col-4 no-border radius-lg-top">
                <view class="action">
                    <text class="text-xl text-bold">预约订单</text>
                </view>
                <view class="action">
                    <navigator url="/pages/nurse/appointment/list">
                        <text class="text-lg">全部预约
                            <text class="cuIcon-right"></text>
                        </text>
                    </navigator>
                </view>
            </view>
            <view class="cu-list grid col-4 no-border text-black  padding-bottom radius-lg-bottom">
                <view class="cu-item" v-for="(item,index) in appointmentMenu" :key="index">
                    <navigator :url="item.url">
                        <view class="text-shadow text-df" :class="'cuIcon-'+item.icon +' text-'+item.icon">
                            <view class="cu-tag badge" v-if="item.badge!==0">
                                <block>{{ item.badge }}</block>
                            </view>
                        </view>
                        <text>{{ item.label }}</text>
                    </navigator>
                </view>
            </view>
        </view>
        <view class="cu-list margin padding-xs menu radius-lg  solid shadow bg-white">
            <view v-if="nurseInfo" class="cu-item">
                <view class="content">
                    <text class="cuIcon-card text-grey"></text>
                    <text class="text-black">职工编号</text>
                </view>
                <view class="action">
                    <text class="text-grey text-sm">{{ nurseInfo?.jobNum }}</text>
                </view>
            </view>
            <view v-if="nurseInfo" class="cu-item arrow" @click="updateInfo">
                <view class="content">
                    <text class="cuIcon-writefill text-grey"></text>
                    <text class="text-black">资料编辑</text>
                </view>
            </view>
            <view v-if="!nurseInfo" class="cu-item arrow" @click="perfectInfo">
                <view class="content">
                    <text class="cuIcon-discoverfill text-grey"></text>
                    <text class="text-black">完善资料</text>
                </view>
            </view>
        </view>
    </view>
</template>

<script setup lang="ts">
import {ref} from 'vue';
import api from '@/api'
import {onHide, onShow} from "@dcloudio/uni-app";


const nurseInfo = ref()
onShow(() => {
    api.nurse.info().then((res: any) => {
        if (res && res.data.data) {
            nurseInfo.value = res.data.data
            getAppointment()
        }
    })
})
onHide(() => {
    appointmentMenu.value.forEach(tmp => {
        tmp.badge = 0
    })
})

const appointmentMenu = ref([
    {
        url: '/pages/nurse/appointment/list?e=1',
        icon: 'activity',
        label: '已预约',
        badge: 0,
        color: 'red'
    },
    {
        url: '/pages/nurse/appointment/list?e=2',
        icon: 'all',
        label: '进行中',
        badge: 0,
        color: 'red'
    },
    {
        url: '/pages/nurse/appointment/list?e=3',
        icon: 'mark',
        label: '待回访',
        badge: 0,
        color: 'red'
    },
    {
        url: '/pages/nurse/appointment/list?e=4',
        icon: 'squarecheck',
        label: '已完成',
        badge: 0,
        color: 'red'
    }
])
const getAppointment = () => {
    api.appointment.list({
        pageNo: 1,
        pageSize: 9999,
        orParams: '{}',
        andParams: JSON.stringify({
            nurseUsername: nurseInfo.value.username
        }),
        orderParams: '{}',
    }).then(res => {
        if (res && res.data.code === 0) {
            let tmp = res.data.data.records
            tmp.forEach((t: { status: number; }) => {
                let id = t.status - 1
                if (id < 3) {
                    appointmentMenu.value.at(id)['badge']++
                }
            })
        }
    })
}


const updateInfo = () => {
    uni.navigateTo({
        url: '/pages/nurse/info/update'
    })
}
const perfectInfo = () => {
    uni.navigateTo({
        url: '/pages/nurse/info/create'
    })
}
</script>

<style>

</style>